//
//  RepairController.m
//  PropertyMananger
//
//  Created by bh on 17/1/13.
//  Copyright © 2017年 BH. All rights reserved.
//

#import "RepairController.h"
#import "HydroRepairController.h"
#import "PublicRepairController.h"

@interface RepairController ()

@end

@implementation RepairController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self initTitleViewName:@"报修"];
    
    [self createSegmentUI];
    
    
}

- (void)createSegmentUI
{
    PublicRepairController * publicVC = [[PublicRepairController alloc]init];
    [self addChildViewController:publicVC];
    HydroRepairController * hydroVC = [[HydroRepairController alloc]init];
    [self addChildViewController:hydroVC];

    NSArray * controllers = @[publicVC,hydroVC];
    
    NSArray *titleArray =@[@"公共报修",@"水电报修"];
    self.bottomSView = [[SGSegmentedControlBottomView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    self.bottomSView.childViewController = controllers;
    self.bottomSView.backgroundColor = [UIColor clearColor];
    self.bottomSView.delegate = self;
    
    //_bottomView.scrollEnabled = NO;
    [self.view addSubview:self.bottomSView];
    
    self.topSView = [SGSegmentedControlStatic segmentedControlWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 44) delegate:self childVcTitle:titleArray indicatorIsFull:NO];
    // 必须实现的方法
    [self.topSView SG_setUpSegmentedControlType:^(SGSegmentedControlStaticType *segmentedControlStaticType, NSArray *__autoreleasing *nomalImageArr, NSArray *__autoreleasing *selectedImageArr) {
        
    }];
    self.topSView.selectedIndex = 0;
    [self.view addSubview:self.topSView];
}

- (void)SGSegmentedControlStatic:(SGSegmentedControlStatic *)segmentedControlStatic didSelectTitleAtIndex:(NSInteger)index {
    NSLog(@"index - - %ld", (long)index);
    // 计算滚动的位置
    CGFloat offsetX = index * self.view.frame.size.width;
    self.bottomSView.contentOffset = CGPointMake(offsetX, 0);
    [self.bottomSView showChildVCViewWithIndex:index outsideVC:self];
}

#pragma mark - UIScrollViewDelegate
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    
    // 计算滚动到哪一页
    NSInteger index = scrollView.contentOffset.x / scrollView.frame.size.width;
    
    // 1.添加子控制器view
    [self.bottomSView showChildVCViewWithIndex:index outsideVC:self];
    
    // 2.把对应的标题选中
    [self.topSView changeThePositionOfTheSelectedBtnWithScrollView:scrollView];
}


@end
